<?php

namespace App\Library\Rules;

use \Illuminate\Contracts\Validation\Rule;

class PriceRule extends BaseRule implements Rule
{
    private string $errorMessage = '金额错误';

    public function passes($attribute, $value)
    {
        $this->errorMessage = $attribute . ' ' . $this->errorMessage;
        if (!aesDecrypt($value)) return false;
        else if (!is_numeric(aesDecrypt($value))) return false;
        else if (aesDecrypt($value) < 0) return false;
        return true;
    }

    public function message(): string
    {
        return $this->errorMessage;
    }
}
